/**
 * 
 */
package ptvv.automatons;

import ptvv.system.DefPortAutomaton;
import ptvv.system.OutputPort;

/**
 * @author 01
 * 
 */
public class Dummy extends DefPortAutomaton {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		

	}

	public Dummy(String name) {
		this.setName(name);
	}

	@Override
	public void starting() throws InterruptedException {

		// System.out.println("waiting");
		eventQueue.take();
	}

	@Override
	public void ready() throws InterruptedException {
		
		// if (inputPort.peek() != null)
		// System.out.println(inputPorts.size());
		//System.out.println("size of queue: " + inputPorts.get(0).queue.size());
		if (inputPorts.size() > 0)
			message = inputPorts.get(0).queue.take();

	}

	@Override
	public void running() throws InterruptedException {
		
		// if (message!=null)
		message = (Integer.parseInt(message) + 1) + "";
		outputPorts.get(0).queue.add(message);

		try {
			//Thread.sleep(100000);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}

	}

	@Override
	public void suspended() throws InterruptedException {
		

	}

	@Override
	public void end() throws InterruptedException {
		// logger.log(this.getName() + ": " + message);
		System.out.println(this.getName() + ": " + message);

		
		for (OutputPort op : this.outputPorts) {
			logger.log("Sending");
			// outputPorts.get(0).sendMessage();
			op.sendInput();
			op.sendStart();

		}
	}

	@Override
	public void dead() throws InterruptedException {
		
		// System.out.println("Done");
	}

}
